
#define abs(x) (x<0?-x:x)

void roberts_c (unsigned char *src, unsigned char *dst, int h, int w, int row_size) {
unsigned char pxls,pxlr;
int result = 0;
int filtroX,filtroY;
unsigned char *pxl,*pxlaux;
unsigned char *grabar, *grabaraux;
int i,j;
grabar = dst;
pxl = src;
pxlaux = pxl;
grabaraux =grabar;

	for(i = 0; i < h - 1; i++){
		pxl = pxlaux;
                grabar = grabaraux;
	    for(j = 0; j < w -1; j++){
		result = 0;       
		pxls = *pxl;

	//	si src es un char *, entonces
	//	*(src + FILA * (ancho_fila) + COLUMNA) es el elemento FILA, COLUMNA de la matriz

		pxlr = *(pxl + row_size +1);

		filtroX = pxls - pxlr;

		pxls = *(pxl + 1);
		pxlr = *(pxl + row_size);

		filtroY = pxls - pxlr;

		filtroX = (int) abs(filtroX);
		filtroY = (int) abs(filtroY);

		result  = filtroX + filtroY;
                
		if(result  > 0xFF){
			*grabar = (unsigned char) 0xFF;
		} else {
			*grabar = (unsigned char)result;
		}
 
		pxl++;
		grabar++;
	    }	    
	    pxlaux = pxlaux + row_size;
            grabaraux = grabaraux + row_size;
	}
}
